package com.multicert.hackathon;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import com.multicert.hackathon.blmanager.BaselineManagerImpl;

/**
 * @author rui.baeta@multicert.com
 */
@Mojo(name = "create-baseline")
public class CreateBaselineMojo extends AbstractBaselineMojo {

    /**
     * This is the baseline name. Ex: BL-ARR, BL-ANA, BL-ENT-01, BL-ENT-02..., BL-FEC.
     */
    @Parameter(property = "create-baseline.baselineName", required = true)
    protected String baselineName;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        getLog().info(String.format("Creating baseline '%s' for project '%s'...", baselineName, projectId));

        setBaselineManager(new BaselineManagerImpl(this.alfrescoUrl, this.username, this.password));
        try {
            getBaselineManager().createBaseline(projectId, baselineName);
            getLog().info(String.format("Baseline '%s' created successfully.", baselineName));

        } catch (Exception e) {
            getLog().error(e);
            throw new MojoFailureException(e.getMessage());
        }
    }
}
